﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Dummy
{
    public class PickedButtonInfo
    {
        public char character { get; private set; }
        private Button ui;

        public static PickedButtonInfo LastPickedButtonInfo;
        private static PickedButtonInfo[] _pickedButtonInfoList = new PickedButtonInfo[32];

        public PickedButtonInfo(StackPanel _pickedCharsUI, char _character)
        {
            character = _character;
            ui = new Button();
            ui.Content = _character;
            ui.Width = 30;
            ui.Height = 30;
            ui.FontSize = 18;
            ui.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            ui.Margin = new Thickness(2);
            ui.Background = null;
            ui.Click += PickChar_Button_Click;
            _pickedCharsUI.Children.Add(ui);
        }

        private void PickChar_Button_Click(object sender, RoutedEventArgs e)
        {
            BattlefieldGameInfo.PickCharacter(this.character);
            PickedButtonInfo.UncolourLastPickedChar();
            PickedButtonInfo.LastPickedButtonInfo = this;
            this.ui.Background = new SolidColorBrush(Colors.Blue);
        }

        public static void Init(MainPage UI)
        {
            string[] charsru = new string[] { "а", "б", "в", "г", "д", "е", "ж", "з", "и", "й", "к", "л", "м", "н", 
                          "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я" };

            UI.sp_chars1.Children.Clear(); //after debug
            for (int i = 0; i < 32; i++)
            {
                if (i < 11)
                    _pickedButtonInfoList[i] = new PickedButtonInfo(UI.sp_chars1, charsru[i][0]);
                else if (i < 22)
                    _pickedButtonInfoList[i] = new PickedButtonInfo(UI.sp_chars2, charsru[i][0]);
                else
                    _pickedButtonInfoList[i] = new PickedButtonInfo(UI.sp_chars3, charsru[i][0]);
            }
        }

        public static void UncolourLastPickedChar()
        {
            if (LastPickedButtonInfo != null)
                LastPickedButtonInfo.ui.Background = null;
        }

        public static void SwitchButtons(bool isEnabled)
        {
            for (int i = 0; i < 32; i++)
                _pickedButtonInfoList[i].ui.IsEnabled = isEnabled;
        }
    }
}
